<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="&{param.package}">
	<resultMap type="map" id="&{param.voClassName}Map">
		<id property="id" column="id" javaType="int"/>
        <@loop.for_{id}>
        <result property="&{param.voFieldName}" column="&{param.tableFieldName}"/>
        <@loop.for_end>
	</resultMap>

    <!-- insert -->
	<insert id="insert" parameterType="Map" useGeneratedKeys="true" keyProperty="id">
		insert into &{param.tableName}
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<@loop.for_{id,update_time}>
            <if test="&{param.voFieldName} != null and &{param.voFieldName} != ''">
                &{param.tableFieldName},
            </if>
			<@loop.for_end>
		</trim>
		values
		<trim prefix="(" suffix=")" suffixOverrides=",">
		    <@loop.for_{id,update_time}>
            <if test="&{param.voFieldName} != null and &{param.voFieldName} != ''">
                #{&{param.voFieldName}, jdbcType=&{param.jdbcType}},
            </if>
            <@loop.for_end>
		</trim>
	</insert>

    <!-- delete -->
	<delete id="delete" parameterType="Map">
		delete from &{param.tableName}
		where
			id = #{id, jdbcType=BIGINT}
	</delete>

    <!-- update -->
	<update id="update" parameterType="Map">
		update &{param.tableName}
		<set>
			<@loop.for_{id,create_time}>
            <if test="&{param.voFieldName} != null and &{param.voFieldName} != ''">
                &{param.tableFieldName} = #{&{param.voFieldName}, jdbcType=&{param.jdbcType}},
            </if>
            <@loop.for_end>
		</set>
		where id = #{id}
	</update>

    <!-- select -->
	<select id="info" parameterType="Map" resultType="&{param.voLowerClassName}">
		select
			<@loop.for_{id}>
            &{param.tableFieldName} as &{param.voFieldName},
            <@loop.for_end>
			id
		from &{param.tableName}
		<where>
			<@loop.for>
            <if test="&{param.voFieldName} != null and &{param.voFieldName} != ''">
                and &{param.tableFieldName} = #{&{param.voFieldName}, jdbcType=&{param.jdbcType}}
            </if>
            <@loop.for_end>
		</where>
	</select>

	<select id="list" parameterType="Map" resultType="&{param.voLowerClassName}">
        select
            <@loop.for_{id}>
            &{param.tableFieldName} as &{param.voFieldName},
            <@loop.for_end>
            id
        from &{param.tableName}
        <where>
            <@loop.for>
            <if test="&{param.voFieldName} != null and &{param.voFieldName} != ''">
                and &{param.tableFieldName} = #{&{param.voFieldName}, jdbcType=&{param.jdbcType}}
            </if>
            <@loop.for_end>
        </where>
    </select>
</mapper>